package com.example.springbootoauth2jwtclientserver.controller;

import com.example.springbootoauth2jwtclientserver.exception.AjaxResponse;
import com.example.springbootoauth2jwtclientserver.security.OAuth2ResourceRestTemplateUtil;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping(value = "/res")
public class ResController {

    private RestTemplate restTemplate;

    public ResController(RestTemplateBuilder restTemplateBuilder) {
        this.restTemplate = restTemplateBuilder.build();
    }

    @RequestMapping(value = "/res1")
    public AjaxResponse getRes(){
        return restTemplate.getForObject("http://localhost:8088/res/res1",AjaxResponse.class);
    }

    @RequestMapping(value = "/user")
    public AjaxResponse getUser(){
        return restTemplate.getForObject("http://localhost:8088/user",null,AjaxResponse.class);
    }

    @RequestMapping(value = "/rbac")
    public AjaxResponse getRBAC(){
        return restTemplate.getForObject("http://localhost:8088/rbac",AjaxResponse.class);
    }
}
